{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c0d26ca-97a2-4dcb-bc44-696b3ded832c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.edge.options import Options\n",
    "from selenium.webdriver.edge.service import Service\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.common.by import By\n",
    "import random\n",
    "\n",
    "# 配置参数\n",
    "options = Options()\n",
    "options.add_argument(\"--headless\")\n",
    "options.add_argument(\"--disable-gpu\")\n",
    "options.add_argument(\"--window-size=1920x1080\")\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0\")\n",
    "options.add_experimental_option(\"excludeSwitches\", [\"enable-automation\"])\n",
    "\n",
    "\n",
    "# 初始化驱动\n",
    "service = Service(r'D:/项目实践/a.jupyter/edge/edgedriver_win64/msedgedriver.exe')\n",
    "driver = webdriver.Edge(service=service, options=options)\n",
    "\n",
    "#打开浏览器\n",
    "driver = webdriver.Edge()\n",
    "\n",
    "for i in range(1,30):\n",
    "\n",
    "    #打开网站\n",
    "    driver.get('https://www.wjx.cn/vm/PMZXWNX.aspx')\n",
    "   \n",
    "    #开始作答\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[1]/div[3]/div/div\").click()\n",
    "    x_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[2]/div\"]\n",
    "    age_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[2]/div\"]\n",
    "    job_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[2]/div\"]\n",
    "    time_list=['/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[4]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[1]/div\"]\n",
    "    guanzhu_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[4]/div\",'/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[3]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[1]/div\"]\n",
    "    shenbian_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[1]/div\"]\n",
    "    leixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[1]/div\"]          \n",
    "   \n",
    "    #单选元素随机\n",
    "    x_list_element = random.choice(x_list)\n",
    "    age_list_element = random.choice(age_list)\n",
    "    job_list_element = random.choice(job_list)\n",
    "    time_list_element = random.choice(time_list)\n",
    "    guanzhu_list_element = random.choice(guanzhu_list)\n",
    "    shenbian_list_element = random.choice(shenbian_list)\n",
    "    leixing_list_element = random.choice(leixing_list)\n",
    "    #点击单选按钮\n",
    "    driver.find_element(By.XPATH, x_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, age_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, job_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, time_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, guanzhu_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, shenbian_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, leixing_list_element).click()\n",
    "    #多选\n",
    "    liaojieleixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[7]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[1]/div\"]\n",
    "    cuoshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[1]/div\"]\n",
    "    pinlv_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[1]/div\"]\n",
    "    chuli_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]\n",
    "    zhishi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[1]/div\"]\n",
    "    xingshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[1]/div\"]\n",
    "    yindyu_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]\n",
    "    #生成随机数\n",
    "    num_1 = random.randint(1,5)\n",
    "    num_2 = random.randint(1,5)\n",
    "    num_3 = random.randint(1,4)\n",
    "    num_4 = random.randint(1,5)\n",
    "    num_5 = random.randint(1,5)\n",
    "    num_6 = random.randint(1,4)\n",
    "    #多选随机\n",
    "    liaojieleixing_list_element= random.sample(liaojieleixing_list, k=num_1)\n",
    "    cuoshi_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "    pinlv_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "    chuli_list_element= random.sample(pinlv_list, k=num_3)\n",
    "    zhishi_list_element= random.sample(zhishi_list, k=num_4)\n",
    "    xingshi_list_element= random.sample(xingshi_list, k=num_5)\n",
    "    yindui_list_element= random.sample(yindyu_list, k=num_6)\n",
    "    #多选点击事件\n",
    "    for xpath in liaojieleixing_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in cuoshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in chuli_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in pinlv_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in zhishi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in xingshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in yindui_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    #提交按钮\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[3]/form/div[11]/div[10]/div[3]/div/div\").click()\n",
    "    # #退出浏览器\n",
    "    # driver.quit()\n",
    "    #刷新网站\n",
    "    time.sleep(3)\n",
    "    driver.refresh()\n",
    "    time.sleep(3)\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "84101119-a774-4974-8506-084ca9db75b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "# from selenium.webdriver.edge.service import Service\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.support import expected_conditions as EC\n",
    "from selenium.webdriver.chrome.options import Options\n",
    "import random\n",
    "import time  # 确保已导入time模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a54518ff-4f80-4d30-a3b6-7febca5bf6d3",
   "metadata": {},
   "outputs": [
    {
     "ename": "TimeoutException",
     "evalue": "Message: \nStacktrace:\n\tGetHandleVerifier [0x00007FF74BB5A545+20677]\n\tsimdutf::get_active_implementation [0x00007FF74BAB6CF0+491296]\n\tMicrosoft::Applications::Events::EventProperty::to_string [0x00007FF74BDAD75A+1807418]\n\t(No symbol) [0x00007FF74B8F72AC]\n\t(No symbol) [0x00007FF74B8F758B]\n\t(No symbol) [0x00007FF74B9385A7]\n\t(No symbol) [0x00007FF74B91849F]\n\t(No symbol) [0x00007FF74B8ED6ED]\n\t(No symbol) [0x00007FF74B935D61]\n\t(No symbol) [0x00007FF74B9181C3]\n\t(No symbol) [0x00007FF74B8ECC36]\n\t(No symbol) [0x00007FF74B8EC0C4]\n\t(No symbol) [0x00007FF74B8ECA63]\n\t(No symbol) [0x00007FF74B9D5BDD]\n\t(No symbol) [0x00007FF74B9E2042]\n\t(No symbol) [0x00007FF74B9DAA03]\n\tMicrosoft::Applications::Events::EventProperty::to_string [0x00007FF74BC342AA+262026]\n\tsimdutf::get_active_implementation [0x00007FF74BAC4421+546385]\n\tsimdutf::get_active_implementation [0x00007FF74BABD6D4+518404]\n\tsimdutf::get_active_implementation [0x00007FF74BABD819+518729]\n\tsimdutf::get_active_implementation [0x00007FF74BAAF3C6+460278]\n\tBaseThreadInitThunk [0x00007FF996BF259D+29]\n\tRtlUserThreadStart [0x00007FF99726AF38+40]\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTimeoutException\u001b[0m                          Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[7], line 22\u001b[0m\n\u001b[0;32m     20\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m     21\u001b[0m     driver\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://www.wjx.cn/vm/PMZXWNX.aspx\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 22\u001b[0m     \u001b[43mWebDriverWait\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdriver\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m15\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43muntil\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m     23\u001b[0m \u001b[43m        \u001b[49m\u001b[43mEC\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpresence_of_element_located\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[43mBy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mID\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43msurveySubmit\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     24\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m     25\u001b[0m     \u001b[38;5;66;03m# 执行后续操作...\u001b[39;00m\n\u001b[0;32m     26\u001b[0m \u001b[38;5;28;01mfinally\u001b[39;00m:\n\u001b[0;32m     27\u001b[0m     driver\u001b[38;5;241m.\u001b[39mquit()\n",
      "File \u001b[1;32mD:\\miniconda3\\lib\\site-packages\\selenium\\webdriver\\support\\wait.py:146\u001b[0m, in \u001b[0;36mWebDriverWait.until\u001b[1;34m(self, method, message)\u001b[0m\n\u001b[0;32m    144\u001b[0m         \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m    145\u001b[0m     time\u001b[38;5;241m.\u001b[39msleep(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_poll)\n\u001b[1;32m--> 146\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m TimeoutException(message, screen, stacktrace)\n",
      "\u001b[1;31mTimeoutException\u001b[0m: Message: \nStacktrace:\n\tGetHandleVerifier [0x00007FF74BB5A545+20677]\n\tsimdutf::get_active_implementation [0x00007FF74BAB6CF0+491296]\n\tMicrosoft::Applications::Events::EventProperty::to_string [0x00007FF74BDAD75A+1807418]\n\t(No symbol) [0x00007FF74B8F72AC]\n\t(No symbol) [0x00007FF74B8F758B]\n\t(No symbol) [0x00007FF74B9385A7]\n\t(No symbol) [0x00007FF74B91849F]\n\t(No symbol) [0x00007FF74B8ED6ED]\n\t(No symbol) [0x00007FF74B935D61]\n\t(No symbol) [0x00007FF74B9181C3]\n\t(No symbol) [0x00007FF74B8ECC36]\n\t(No symbol) [0x00007FF74B8EC0C4]\n\t(No symbol) [0x00007FF74B8ECA63]\n\t(No symbol) [0x00007FF74B9D5BDD]\n\t(No symbol) [0x00007FF74B9E2042]\n\t(No symbol) [0x00007FF74B9DAA03]\n\tMicrosoft::Applications::Events::EventProperty::to_string [0x00007FF74BC342AA+262026]\n\tsimdutf::get_active_implementation [0x00007FF74BAC4421+546385]\n\tsimdutf::get_active_implementation [0x00007FF74BABD6D4+518404]\n\tsimdutf::get_active_implementation [0x00007FF74BABD819+518729]\n\tsimdutf::get_active_implementation [0x00007FF74BAAF3C6+460278]\n\tBaseThreadInitThunk [0x00007FF996BF259D+29]\n\tRtlUserThreadStart [0x00007FF99726AF38+40]\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.edge.options import Options\n",
    "from selenium.webdriver.edge.service import Service\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.common.by import By\n",
    "import random\n",
    "\n",
    "# 配置参数\n",
    "options = Options()\n",
    "options.add_argument(\"--headless\")\n",
    "options.add_argument(\"--disable-gpu\")\n",
    "options.add_argument(\"--window-size=1920x1080\")\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0\")\n",
    "options.add_experimental_option(\"excludeSwitches\", [\"enable-automation\"])\n",
    "\n",
    "# 初始化驱动\n",
    "service = Service(r'D:/项目实践/a.jupyter/edge/edgedriver_win64/msedgedriver.exe')\n",
    "driver = webdriver.Edge(service=service, options=options)\n",
    "\n",
    "try:\n",
    "    driver.get(\"https://www.wjx.cn/vm/PMZXWNX.aspx\")\n",
    "    WebDriverWait(driver, 15).until(\n",
    "        EC.presence_of_element_located((By.ID, \"surveySubmit\"))\n",
    "    )\n",
    "    # 执行后续操作...\n",
    "finally:\n",
    "    driver.quit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8e704b45-0ae0-4e5d-8802-9a4f8b0e0d01",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "WebDriver.__init__() got an unexpected keyword argument 'executable_path'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 11\u001b[0m\n\u001b[0;32m      8\u001b[0m options\u001b[38;5;241m.\u001b[39madd_experimental_option(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mexcludeSwitches\u001b[39m\u001b[38;5;124m\"\u001b[39m, [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124menable-automation\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m     10\u001b[0m \u001b[38;5;66;03m# 初始化驱动（需替换实际驱动路径）\u001b[39;00m\n\u001b[1;32m---> 11\u001b[0m driver \u001b[38;5;241m=\u001b[39m \u001b[43mwebdriver\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mChrome\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m     12\u001b[0m \u001b[43m    \u001b[49m\u001b[43mexecutable_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m/usr/local/bin/chromedriver\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m     13\u001b[0m \u001b[43m    \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\n\u001b[0;32m     14\u001b[0m \u001b[43m)\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: WebDriver.__init__() got an unexpected keyword argument 'executable_path'"
     ]
    }
   ],
   "source": [
    "# 配置浏览器参数\n",
    "options = Options()\n",
    "options.add_argument(\"--headless=new\")\n",
    "options.add_argument(\"--disable-gpu\")\n",
    "options.add_argument(\"--no-sandbox\")\n",
    "options.add_argument(\"--window-size=1920,1080\")\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\")\n",
    "options.add_experimental_option(\"excludeSwitches\", [\"enable-automation\"])\n",
    "\n",
    "# 初始化驱动（需替换实际驱动路径）\n",
    "driver = webdriver.Chrome(\n",
    "    executable_path='/usr/local/bin/chromedriver',\n",
    "    options=options\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "beae700c-b6ab-4501-b249-4ff3d70ebd2c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9c0614f-69c6-4724-977f-7197f3fe1e55",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 配置浏览器选项\n",
    "options = Options()\n",
    "options.add_argument(\"--headless\")  # 无头模式\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\")\n",
    "driver = webdriver.Chrome(options=options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "67e2ea82-da90-44cc-9afe-2d502476b649",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n",
      "50\n",
      "51\n",
      "52\n",
      "53\n",
      "54\n",
      "55\n",
      "56\n",
      "57\n",
      "58\n",
      "59\n",
      "60\n",
      "61\n",
      "62\n",
      "63\n",
      "64\n",
      "65\n",
      "66\n",
      "67\n",
      "68\n",
      "69\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "80\n",
      "81\n",
      "82\n",
      "83\n",
      "84\n",
      "85\n",
      "86\n",
      "87\n",
      "88\n",
      "89\n",
      "90\n",
      "91\n",
      "92\n",
      "93\n",
      "94\n",
      "95\n",
      "96\n",
      "97\n",
      "98\n",
      "99\n"
     ]
    }
   ],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.edge.options import Options\n",
    "from selenium.webdriver.edge.service import Service\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.common.by import By\n",
    "import random\n",
    "\n",
    "# 配置参数\n",
    "options = Options()\n",
    "options.add_argument(\"--headless\")\n",
    "options.add_argument(\"--disable-gpu\")\n",
    "options.add_argument(\"--window-size=1920x1080\")\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0\")\n",
    "options.add_experimental_option(\"excludeSwitches\", [\"enable-automation\"])\n",
    "\n",
    "\n",
    "# 初始化驱动\n",
    "service = Service(r'D:/项目实践/a.jupyter/edge/edgedriver_win64/msedgedriver.exe')\n",
    "driver = webdriver.Edge(service=service, options=options)\n",
    "\n",
    "#打开浏览器\n",
    "driver = webdriver.Edge()\n",
    "\n",
    "for i in range(1,100):\n",
    "\n",
    "    #打开网站\n",
    "    driver.get('https://www.wjx.cn/vm/PMZXWNX.aspx')\n",
    "   \n",
    "    #开始作答\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[1]/div[3]/div/div\").click()\n",
    "    x_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[2]/div\"]\n",
    "    age_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[2]/div\"]\n",
    "    job_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[2]/div\"]\n",
    "    time_list=['/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[4]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[1]/div\"]\n",
    "    guanzhu_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[4]/div\",'/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[3]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[1]/div\"]\n",
    "    shenbian_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[1]/div\"]\n",
    "    leixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[1]/div\"]          \n",
    "   \n",
    "    #单选元素随机\n",
    "    x_list_element = random.choice(x_list)\n",
    "    age_list_element = random.choice(age_list)\n",
    "    job_list_element = random.choice(job_list)\n",
    "    time_list_element = random.choice(time_list)\n",
    "    guanzhu_list_element = random.choice(guanzhu_list)\n",
    "    shenbian_list_element = random.choice(shenbian_list)\n",
    "    leixing_list_element = random.choice(leixing_list)\n",
    "    #点击单选按钮\n",
    "    driver.find_element(By.XPATH, x_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, age_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, job_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, time_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, guanzhu_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, shenbian_list_element).click()\n",
    "    time.sleep(1)\n",
    "    driver.find_element(By.XPATH, leixing_list_element).click()\n",
    "    #多选\n",
    "    liaojieleixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[7]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[1]/div\"]\n",
    "    cuoshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[1]/div\"]\n",
    "    pinlv_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[1]/div\"]\n",
    "    chuli_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]\n",
    "    zhishi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[1]/div\"]\n",
    "    xingshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[1]/div\"]\n",
    "    yindyu_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]\n",
    "    #生成随机数\n",
    "    num_1 = random.randint(1,5)\n",
    "    num_2 = random.randint(1,5)\n",
    "    num_3 = random.randint(1,4)\n",
    "    num_4 = random.randint(1,5)\n",
    "    num_5 = random.randint(1,5)\n",
    "    num_6 = random.randint(1,4)\n",
    "    #多选随机\n",
    "    liaojieleixing_list_element= random.sample(liaojieleixing_list, k=num_1)\n",
    "    cuoshi_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "    chuli_list_element= random.sample(pinlv_list, k=num_3)\n",
    "    zhishi_list_element= random.sample(zhishi_list, k=num_4)\n",
    "    xingshi_list_element= random.sample(xingshi_list, k=num_5)\n",
    "    yindui_list_element= random.sample(yindyu_list, k=num_6)\n",
    "    #多选点击事件\n",
    "    for xpath in liaojieleixing_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in cuoshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in chuli_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in zhishi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in xingshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    for xpath in yindui_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        delay = random.uniform(1, 2)\n",
    "        time.sleep(delay)\n",
    "    #提交按钮\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[3]/form/div[11]/div[10]/div[3]/div/div\").click()\n",
    "    # #退出浏览器\n",
    "    # driver.quit()\n",
    "    #刷新网站\n",
    "    time.sleep(3)\n",
    "    driver.refresh()\n",
    "    time.sleep(3)\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "875135f2-4da3-442e-88a9-88700b01b78c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#打开浏览器\n",
    "driver = webdriver.Edge()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0c081947-0466-4aad-b1db-b5f17e2d996e",
   "metadata": {},
   "outputs": [],
   "source": [
    "#打开网站\n",
    "driver.get('https://www.wjx.cn/vm/PMZXWNX.aspx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "f477e2b3-b691-4e21-a8cb-58c104091f4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#开始作答\n",
    "driver.find_element(By.XPATH, \"/html/body/div[1]/div[3]/div/div\").click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "353458e7-8b86-4090-b25a-0767aee16324",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[2]/div\"]\n",
    "age_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[2]/div\"]\n",
    "job_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[2]/div\"]\n",
    "time_list=['/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[4]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[1]/div\"]\n",
    "guanzhu_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[4]/div\",'/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[3]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[1]/div\"]\n",
    "shenbian_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[1]/div\"]\n",
    "leixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[1]/div\"]          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d442363e-9267-4746-b4f3-abce871368a0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "21d08d03-3b5f-4c43-b5c8-be2b38cd5e0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#单选元素随机\n",
    "x_list_element = random.choice(x_list)\n",
    "age_list_element = random.choice(age_list)\n",
    "job_list_element = random.choice(job_list)\n",
    "time_list_element = random.choice(time_list)\n",
    "guanzhu_list_element = random.choice(guanzhu_list)\n",
    "shenbian_list_element = random.choice(shenbian_list)\n",
    "leixing_list_element = random.choice(leixing_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ea272da5-dcf4-49a2-a9c8-b15bf7b28d8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#点击单选按钮\n",
    "driver.find_element(By.XPATH, x_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, age_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, job_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, time_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, guanzhu_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, shenbian_list_element).click()\n",
    "time.sleep(1)\n",
    "driver.find_element(By.XPATH, leixing_list_element).click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "d8844d49-e5cb-4dab-8696-3a6d322b4402",
   "metadata": {},
   "outputs": [],
   "source": [
    "#多选\n",
    "liaojieleixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[7]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[6]/div[2]/div[1]/div\"]\n",
    "cuoshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[7]/div[2]/div[1]/div\"]\n",
    "pinlv_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[8]/div[2]/div[1]/div\"]\n",
    "chuli_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]\n",
    "zhishi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[12]/div[2]/div[1]/div\"]\n",
    "xingshi_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[13]/div[2]/div[1]/div\"]\n",
    "yindyu_list = [\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[11]/div[2]/div[1]/div\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "04eac2ad-f928-45c4-84b0-769eb8925b4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "num_1 = random.randint(1,7)\n",
    "num_2 = random.randint(1,6)\n",
    "num_3 = random.randint(1,5)\n",
    "num_4 = random.randint(1,5)\n",
    "num_5 = random.randint(1,6)\n",
    "num_6 = random.randint(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "f7aaf8c5-42b9-4c0d-bab9-b7e7b70fdab1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#多选随机\n",
    "liaojieleixing_list_element= random.sample(liaojieleixing_list, k=num_1)\n",
    "cuoshi_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "pinlv_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "chuli_list_element= random.sample(pinlv_list, k=num_3)\n",
    "zhishi_list_element= random.sample(zhishi_list, k=num_4)\n",
    "xingshi_list_element= random.sample(xingshi_list, k=num_5)\n",
    "yindui_list_element= random.sample(yindyu_list, k=num_6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "a434a07e-f25e-43d7-85b3-340b52438aaf",
   "metadata": {},
   "outputs": [],
   "source": [
    "for xpath in yindui_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b385f4e2-8a5a-4fbd-b05b-a9d90f898fe7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "abb5b83a-355b-4b03-8989-c722fb10ef0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "#多选点击事件\n",
    "for xpath in liaojieleixing_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in cuoshi_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in chuli_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in pinlv_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in zhishi_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in xingshi_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)\n",
    "for xpath in yindui_list_element:\n",
    "    element = driver.find_element(By.XPATH, xpath)\n",
    "    element.click()\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "69ddbef9-1ad9-4920-88a6-6a51cb7e2051",
   "metadata": {},
   "outputs": [],
   "source": [
    "#提交按钮\n",
    "driver.find_element(By.XPATH, \"/html/body/div[3]/form/div[11]/div[10]/div[3]/div/div\").click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "801fd8bb-2585-4065-b932-19653865b62d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#回退到上一页\n",
    "driver.back() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "5b267c0c-4aa9-4558-adb0-ceba34baf8f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "#刷新网站\n",
    "driver.refresh()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94ebde40-b974-4686-b4c9-40f53559b914",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af2ae0f9-fb77-43db-a1b2-0d9c8e201837",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 配置浏览器选项\n",
    "options = Options()\n",
    "options.add_argument(\"--headless\")  # 无头模式\n",
    "options.add_argument(\"user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36\")\n",
    "driver = webdriver.Chrome(options=options)\n",
    "for i in range(1,10):\n",
    "    #打开浏览器\n",
    "    driver = webdriver.Edge()\n",
    "    #打开网站\n",
    "    driver.get('https://www.wjx.cn/vm/PMZXWNX.aspx')\n",
    "   \n",
    "    #开始作答\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[1]/div[3]/div/div\").click()\n",
    "    x_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[1]/div[2]/div[2]/div\"]\n",
    "    age_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[2]/div[2]/div[2]/div\"]\n",
    "    job_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[6]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[1]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[3]/div[2]/div[2]/div\"]\n",
    "    time_list=['/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[4]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div','/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[2]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[4]/div[2]/div[1]/div\"]\n",
    "    guanzhu_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[4]/div\",'/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[3]/div',\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[5]/div[2]/div[1]/div\"]\n",
    "    shenbian_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[9]/div[2]/div[1]/div\"]\n",
    "    leixing_list=[\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[5]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[4]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[3]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[2]/div\",\"/html/body/div[3]/form/div[11]/div[5]/fieldset/div[10]/div[2]/div[1]/div\"]          \n",
    "   \n",
    "    #单选元素随机\n",
    "    x_list_element = random.choice(x_list)\n",
    "    age_list_element = random.choice(age_list)\n",
    "    job_list_element = random.choice(job_list)\n",
    "    time_list_element = random.choice(time_list)\n",
    "    guanzhu_list_element = random.choice(guanzhu_list)\n",
    "    shenbian_list_element = random.choice(shenbian_list)\n",
    "    leixing_list_element = random.choice(leixing_list)\n",
    "    #生成随机数\n",
    "    num_1 = random.randint(1,7)\n",
    "    num_2 = random.randint(1,6)\n",
    "    num_3 = random.randint(1,5)\n",
    "    num_4 = random.randint(1,5)\n",
    "    num_5 = random.randint(1,6)\n",
    "    num_6 = random.randint(1,5)\n",
    "    #多选随机\n",
    "    liaojieleixing_list_element= random.sample(liaojieleixing_list, k=num_1)\n",
    "    cuoshi_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "    pinlv_list_element= random.sample(cuoshi_list, k=num_2)\n",
    "    chuli_list_element= random.sample(pinlv_list, k=num_3)\n",
    "    zhishi_list_element= random.sample(zhishi_list, k=num_4)\n",
    "    xingshi_list_element= random.sample(xingshi_list, k=num_5)\n",
    "    yindui_list_element= random.sample(yindyu_list, k=num_6)\n",
    "    #多选点击事件\n",
    "    for xpath in liaojieleixing_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in cuoshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in chuli_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in pinlv_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in zhishi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in xingshi_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    for xpath in yindui_list_element:\n",
    "        element = driver.find_element(By.XPATH, xpath)\n",
    "        element.click()\n",
    "        time.sleep(1)\n",
    "    #提交按钮\n",
    "    driver.find_element(By.XPATH, \"/html/body/div[3]/form/div[11]/div[10]/div[3]/div/div\").click()\n",
    "    #退出浏览器\n",
    "    driver.quit()\n",
    "    #刷新网站\n",
    "    driver.refresh()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89d41b38-1d1f-46b1-afca-be93c4dc41a9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a805af3a-4e16-4006-9fac-1c9fffea74af",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e809084-c01b-44b4-a515-bc34bf4baba7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
